/**
 * Created by xwang on 2018-09-12.
 */
var request = require("superagent");
var API = require("./support/const");
var service = require("../../service/log");


/**
 * 检查报告
 * **/
exports.report = {
    list: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };

        let params = req.body;
        request.get(API.report.list)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getList', 'msg': '获取检查报告列表'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },

    check: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let {id} = req.body;
        request.get(API.report.check + id)
            .set(header)
            .query({id: id})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getId', 'msg': '获取检查报告下的检查作业'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    detail: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let {id} = req.body;
        request.get(API.report.detail + id)
            .set(header)
            .query({id: id})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getId', 'msg': '获取检查报告详情'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    update: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.put(API.report.update)
            .type('application/json')
            .set(header)
            .send(JSON.stringify(params))
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '编辑检查报告', 'mark':params }, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    result: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.get(API.report.result)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getList', 'msg': '评估检查报告检查结果'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    submit: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.put(API.report.submit)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '提交检查报告'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    selfCheckReport: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.get(API.report.self_check_report)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getList', 'msg': '自查报告列表'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    selfCheckReportWord: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.get(API.report.self_check_report_word)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getList', 'msg': '下载自查报告文档'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    selfSubmitReport: function (req, res, next) {

        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.post(API.report.self_check_submit_report)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'getList', 'msg': '提交自查报告'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    }

};